#include <SimpleRenderer.h>



void SimpleRenderer::Render(const Wave& currentWave) const
{
	// Clear the screen
	Application::driver->beginScene(true, true, SColor(255,0,0,0));

	// Draw score
	wchar_t scoreString[11];
	memset(scoreString, 0, 11 * sizeof(wchar_t));
	wsprintf(scoreString, L"%0.6d", currentWave.m_currentScore);

	currentWave.m_scoreFont->draw(scoreString, rect<s32>(0, 0, 800, 600), SColor(90, 0, 255, 255), true, true);

	// Draw best score
	wchar_t goalScoreString[16];
	memset(goalScoreString, 0, 16 * sizeof(wchar_t));
	wsprintf(goalScoreString, L"GOAL %0.6d", currentWave.m_goalScore);

	currentWave.m_bestScoreFont->draw(goalScoreString, rect<s32>(0, 0, 800, 30), SColor(90, 255, 255, 255), true, true);

	Render(*currentWave.m_pPlayer);
	
	for (u32 i=0; i < currentWave.m_bulletManager.m_activeEntities.size(); i++)
		Render(*currentWave.m_bulletManager.m_activeEntities.at(i));

	for (u32 i=0; i < currentWave.m_enemyManager.m_activeEntities.size(); i++)
		Render(*currentWave.m_enemyManager.m_activeEntities.at(i));

	Application::driver->endScene();
}

void SimpleRenderer::Render(const Player& player) const
{
	vector2df vPosition = player.GetPosition();
	SColor color = SColor(255,255,237,107);
	f32 radius = player.GetRadius();
	f32 energy = player.GetPercentEnergy();

	// Draw Center
	Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), 2, color, 4);

	// Draw Circle
	// when in Hit state, the player flashes
	if( !player.IsHit() || (Application::gameTime / 150) % 2 == 0 ) // every 0.15 secs he changes its visibility
	{
		Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), radius, color, 20);

		for(f32 i = radius * energy; i > radius * energy / 2; i -= 5)
			Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), i, color, 20);
	}
}

void SimpleRenderer::Render(const Bullet& bullet) const
{
	vector2df vPosition = bullet.GetPosition();
	Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), 2, SColor(255,255,255,0), 2);
}

void SimpleRenderer::Render(const Enemy& enemy) const
{
	vector2df vPosition = enemy.GetPosition();
	f32 radius = enemy.GetRadius();
	Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), radius, SColor(255,255,0,0), 5);
}


void SimpleRenderer::Render(const Follower& enemy) const
{
	vector2df vPosition = enemy.GetPosition();
	f32 radius = enemy.GetRadius();
	Application::driver->draw2DPolygon(position2di((s32)vPosition.X, (s32)vPosition.Y), radius, SColor(255,255,255,0), 7);
}